找传奇、传世资源到传世资源站!

基于android柱面全景图相机应用

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

testlive555
from clipboard
from clipboardfrom clipboard

package qsl.learn;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileOutputStream;import java.util.ArrayList;import android.R.integer;import android.app.Activity;import android.app.AlertDialog;import android.app.ProgressDialog;import android.content.Context;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.content.Intent;import android.content.pm.ActivityInfo;import android.graphics.Bitmap;import android.graphics.Bitmap.CompressFormat;import android.graphics.BitmapFactory;import android.graphics.Color;import android.hardware.Camera;import android.hardware.Camera.PictureCallback;import android.hardware.Sensor;import android.hardware.SensorEvent;import android.hardware.SensorEventListener;import android.hardware.SensorManager;import android.os.AsyncTask;import android.os.Bundle;import android.util.Log;import android.view.Display;import android.view.KeyEvent;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.widget.EditText;import android.widget.FrameLayout;import android.widget.FrameLayout.LayoutParams;import android.widget.ImageView;import android.widget.ImageView.ScaleType;import android.widget.TextView;/** * 全景图拍摄主页面,目前支持两张图片和三张图片的拍摄和合成 * * @author Qin Shulei * */public class MypanoramaActivity extends Activity implementsSensorEventListener, android.view.View.OnClickListener {/** Called when the activity is first created. */private CameraPreview mCameraPreview;private ImageView mImageView;private TextView mXTextView, mYTextView, mZTextView;private Camera mCamera;private ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();private double x = 0;private double y = 0;private double z = 0;private double zLast = 0;private SensorManager mSensorManager;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setFullScreen();setContentView(R.layout.mypanorama);this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);Display display = wm.getDefaultDisplay();int mScreenHeight = display.getHeight();int mScreenWidth = display.getWidth();getCameraInstance();mCameraPreview = new CameraPreview(this, mCamera, mScreenWidth,(int) (mScreenHeight * 0.8));LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT);FrameLayout frameLayout = (FrameLayout) findViewById(R.id.sview);frameLayout.addView(mCameraPreview, params);mImageView = new ImageView(this);mImageView.bringToFront();mImageView.setScaleType(ScaleType.FIT_START);frameLayout.addView(mImageView, params);mImageView.setVisibility(View.GONE);mXTextView = (TextView) findViewById(R.id.x_textview);mYTextView = (TextView) findViewById(R.id.y_textview);mZTextView = (TextView) findViewById(R.id.z_textview);findViewById(R.id.combine_button).setOnClickListener(this);mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);}public Camera getCameraInstance() {if (mCamera == null) {mCamera = Camera.open();}return mCamera;}@Overrideprotected void onResume() {super.onResume();// getCameraInstance();if (mCameraPreview.isPreview) {mCamera.startPreview();}mSensorManager.registerListener(this,mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),SensorManager.SENSOR_DELAY_GAME);}@Overrideprotected void onPause() {mSensorManager.unregisterListener(this);if (mCameraPreview.isPreview) {mCamera.stopPreview();mCameraPreview.isPreview = false;// mCameraPreview.isPreview = false;}mSensorManager.unregisterListener(this);// if (mCamera != null) {//// releaseCamera();// }super.onPause();}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubif (mCamera != null) {releaseCamera();}super.onDestroy();}@Overrideprotected void onStop() {super.onStop();}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {switch (keyCode) {case KeyEvent.KEYCODE_CAMERA:if (!canTakePhotoCheck()) {return true;}if (mCamera != null && event.getRepeatCount() == 0) {zLast = z;mCamera.takePicture(null, null, myjpegCallback);return true;}break;default:break;}return super.onKeyDown(keyCode, event);}private boolean canTakePhotoCheck() {if (bitmaps.size() == 0 && checkHorital()) {return true;}if (checkHorital() && checkZChange()) {return true;}return false;}private boolean checkZChange() {if (bitmaps.size() == 0) {return true;}double zChange = Math.abs(z - zLast);if ((zChange > 19 || zChange < 21)) {return true;}return false;}private boolean checkHorital() {if ((-2 < y && y < 2) || (y < -178 || y > 178) && z > 86) {return true;}return false;}private PictureCallback myjpegCallback = new PictureCallback() {private Bitmap bm;// private void savePicture(String name) {//// String pathString = (name == "" ? photoname (int) z : name)// ".jpg";// File dirFile = new File(Const.PIC_PATH);// if (!dirFile.exists()) {//// dirFile.mkdirs();//// }// File file = new File(Const.PIC_PATH, pathString);// BufferedOutputStream bos = null;// try {// bos = new BufferedOutputStream(new FileOutputStream(file));//// bm.compress(CompressFormat.JPEG, 100, bos);// bos.flush();// bos.close();// PhotoDbAdapter photoDbAdapter = new PhotoDbAdapter(// MypanoramaActivity.this);// photoDbAdapter.open();// photoDbAdapter.createPhoto(file.getName(), file.getPath());// photoDbAdapter.close();// } catch (Exception e) {//// } finally {// bos = null;// }//// bitmaps.add(PhotoUtil.decodeBitmap(file.getPath(), 300));//// MypanoramaActivity.this.mCamera.startPreview();// mCameraPreview.isPreview = true;//// }@Overridepublic void onPictureTaken(byte[] data, Camera camera) {// take photo and stop preview ,save it// Bitmap tempBitmap = mCameraPreview.getDrawingCache();camera.stopPreview();mCameraPreview.isPreview = false;bm = getScalePictureFromData(data, 300);bitmaps.add(bm);// savePicture();Bitmap dispayBitmap = Bitmap.createBitmap(bm, bm.getWidth() * 2 / 3, 0,bm.getWidth() / 3, bm.getHeight());mImageView.setImageBitmap(dispayBitmap);mImageView.setAlpha(150);mImageView.setVisibility(View.VISIBLE);// bm.recycle();camera.startPreview();mCameraPreview.isPreview = true;}private Bitmap getScalePictureFromData(byte[] data, int compareSize) {BitmapFactory.Options options = new BitmapFactory.Options();options.inJustDecodeBounds = true;// 通过这个bitmap获取图片的宽和高Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);if (bitmap == null) {System.out.println("bitmap为空");}float realWidth = options.outWidth;float realHeight = options.outHeight;System.out.println("真实图片高度:" realHeight "宽度:" realWidth);// 计算缩放比int scale = (int) ((realHeight > realWidth ? realHeight : realWidth) / compareSize);if (scale <= 0) {scale = 1;}options.inSampleSize = scale;options.inJustDecodeBounds = false;// 注意这次要把options.inJustDecodeBounds 设为 false,这次图片是要读取出来的。bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);return bitmap;}};private void setFullScreen() {requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);}@Overridepublic void onAccuracyChanged(Sensor sensor, int accuracy) {// TODO Auto-generated method stub}private void releaseCamera() {if (mCamera != null) {mCamera.release();}}@Overridepublic void onSensorChanged(SensorEvent event) {int sensorType = event.sensor.getType();float[] values = event.values;StringBuilder sBuilder = null;switch (sensorType) {case Sensor.TYPE_ORIENTATION:mXTextView.setText("X:" values[0]);x = values[0];if (checkZChange()) {mXTextView.setTextColor(Color.GREEN);} else {mXTextView.setTextColor(Color.RED);}mYTextView.setText("Y:" values[1]);y = values[1];mZTextView.setText("Z:" values[2]);z = values[2];if (checkHorital()) {mYTextView.setTextColor(Color.GREEN);mZTextView.setTextColor(Color.GREEN);} else {mYTextView.setTextColor(Color.RED);mZTextView.setTextColor(Color.GREEN);}break;default:break;}}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.combine_button:combiePicture();break;default:break;}}private void combiePicture() {if (bitmaps.size() < 1) {return;}mCamera.stopPreview();mCameraPreview.isPreview = false;mSensorManager.unregisterListener(this);switch (bitmaps.size()) {case 1:new CombineTask().execute(bitmaps.get(0));break;case 2:new CombineTask().execute(bitmaps.get(0), bitmaps.get(1));break;//case 3://new CombineTask().execute(bitmaps.get(0), bitmaps.get(1),//bitmaps.get(2));//break;//case 4://new CombineTask().execute(bitmaps.get(0), bitmaps.get(1),//bitmaps.get(2), bitmaps.get(3));//break;//case 5://new CombineTask().execute(bitmaps.get(0), bitmaps.get(1),//bitmaps.get(2), bitmaps.get(3), bitmaps.get(4));//break;//case 6://new CombineTask().execute(bitmaps.get(0), bitmaps.get(1),//bitmaps.get(2), bitmaps.get(3), bitmaps.get(4),//bitmaps.get(5));default:Bitmap[] b = new Bitmap[bitmaps.size()];new CombineTask().execute(bitmaps.toArray(b));break;}}private class CombineTask extends AsyncTask<Bitmap, Void, Bitmap> {ProgressDialog mProgressDialog;private String photoname = "bitmap";private EditText photonameEditText;private Bitmap resultBitmap;@Overrideprotected Bitmap doInBackground(Bitmap... params) {Bitmap newBitmap = null;switch (params.length) {case 1:newBitmap = combineForOne(params[0]);break;case 2:Bitmap result1 = params[0];Bitmap result2 = params[1];newBitmap = combineForTwo(result1, result2);break;//case 3://newBitmap = combineForThree(params);//break;////case 4://newBitmap = combineForFour(params);//break;//case 5://newBitmap = combineForFive(params);default:newBitmap = combineForAnyBitmap(params);break;}return newBitmap;}private Bitmap combineForAnyBitmap(Bitmap[] params) {long start = System.currentTimeMillis();int width = params[0].getWidth();int height = params[0].getHeight();ArrayList<CombineBitmap> combineBitmaps = new ArrayList<CombineBitmap>();for (int i = 0; i < params.length; i ) {combineBitmaps.add(new CombineBitmap(CylinderFromRectangle(params[i])));}ArrayList<Offset> offsets = new ArrayList<MypanoramaActivity.CombineTask.Offset>();for (int i = 1; i < params.length; i ) {offsets.add(calculateOffset(combineBitmaps.get(i - 1).pixels,combineBitmaps.get(i).pixels, width, height));}int CoverWidth = width / 3;// int secondCoverWidth = width / 3;Log.d("offset", "计算完毕");combineBitmaps.get(0).setOtherAttr(0, 0, 0,CoverWidth - offsets.get(0).offsetX);for (int i = 1; i < params.length; i ) {combineBitmaps.get(i).setOtherAttr(combineBitmaps.get(i - 1).offsetX 2 * width / 3 offsets.get(i - 1).offsetX,combineBitmaps.get(i - 1).offsetY offsets.get(i - 1).offsetY,combineBitmaps.get(i - 1).rightCoverWith,CoverWidth - offsets.get(i - 1).offsetX);}Log.d("combineBitmap", "创建完毕");int resultWidth = combineBitmaps.get(combineBitmaps.size() - 1).offsetX width;Log.d("resultWidth", Integer.toString(resultWidth));int[] resultPixels = new int[resultWidth * height];Log.d("resultPixels", "分配成功");int pixColor = 0;int layColor = 0;int pixR = 0;int pixG = 0;int pixB = 0;int pixA = 0;int layR = 0;int layG = 0;int layB = 0;int layA = 0;int newR = 0;int newG = 0;int newB = 0;int newA = 0;int checkIdx = 0;int targertIdx = 0;double ratio = 0;int Max = height * width;int resultMax = resultWidth * height;for (int h = 0; h < height; h ) {for (int w = 0; w < width - combineBitmaps.get(0).leftCoverWith; w ) {resultPixels[h * resultWidth w] = combineBitmaps.get(0).pixels[h* width w];}}for (int h = 0; h < height; h ) {for (int w = width - combineBitmaps.get(0).leftCoverWith; w < width; w ) {resultPixels[h * resultWidth w] = combineBitmaps.get(0).pixels[h* width w];}}Log.d("firstPix", "pass");for (int i = 1; i < combineBitmaps.size(); i ) {for (int h = 0; h < height; h ) {for (int w = 0; w < combineBitmaps.get(i).leftCoverWith; w ) {targertIdx = (h combineBitmaps.get(i).offsetY)* resultWidth w combineBitmaps.get(i).offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}checkIdx = h * width w;ratio = (double) w/ combineBitmaps.get(i).leftCoverWith;// 得到这个点在重叠部分的比例基数,以便实现渐变layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = combineBitmaps.get(i).pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, layR));newG = Math.min(255, Math.max(newG, layG));newB = Math.min(255, Math.max(newB, layB));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = combineBitmaps.get(i).leftCoverWith; w < width; w ) {targertIdx = (h combineBitmaps.get(i).offsetY)* resultWidth w combineBitmaps.get(i).offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}resultPixels[targertIdx] = combineBitmaps.get(i).pixels[width* h w];}}Log.d("pic", "pass");// combineBitmaps = null;// secondPixels = null;}bitmaps.clear();for (int i = 0; i < params.length; i ) {params[i].recycle();}bitmaps.clear();Bitmap bitmap = Bitmap.createBitmap(resultWidth, height,Bitmap.Config.RGB_565);bitmap.setPixels(resultPixels, 0, resultWidth, 0, 0, resultWidth,height);long end = System.currentTimeMillis();Log.d("Four_pic_costTime:", Long.toString(end - start));return bitmap;}private Bitmap combineForFive(Bitmap[] params) {long start = System.currentTimeMillis();int width = params[0].getWidth();int height = params[0].getHeight();int[] firstPixels = CylinderFromRectangle(params[0]);int[] secondPixels = CylinderFromRectangle(params[1]);int[] thirdPixels = CylinderFromRectangle(params[2]);int[] fourPixels = CylinderFromRectangle(params[3]);int[] fivePixels = CylinderFromRectangle(params[4]);final Offset firstOffset = calculateOffset(firstPixels,secondPixels, width, height);final Offset secondOffset = calculateOffset(secondPixels,thirdPixels, width, height);final Offset thirdOffset = calculateOffset(thirdPixels, fourPixels,width, height);final Offset fourOffset = calculateOffset(fourPixels, fivePixels,width, height);int CoverWidth = width / 3;// int secondCoverWidth = width / 3;Log.d("offset", "计算完毕");CombineBitmap combineBitmap1 = new CombineBitmap(firstPixels, 0, 0,0, CoverWidth - firstOffset.offsetX);CombineBitmap combineBitmap2 = new CombineBitmap(secondPixels, 2* width / 3 firstOffset.offsetX, firstOffset.offsetY,CoverWidth - firstOffset.offsetX, CoverWidth- secondOffset.offsetX);CombineBitmap combineBitmap3 = new CombineBitmap(thirdPixels,combineBitmap2.offsetX 2 * width / 3 secondOffset.offsetX, combineBitmap2.offsetY secondOffset.offsetY,combineBitmap2.rightCoverWith, CoverWidth- thirdOffset.offsetX);CombineBitmap combineBitmap4 = new CombineBitmap(fourPixels,combineBitmap3.offsetX 2 * width / 3 thirdOffset.offsetX, combineBitmap3.offsetY thirdOffset.offsetY,combineBitmap3.rightCoverWith, CoverWidth- thirdOffset.offsetX);CombineBitmap combineBitmap5 = new CombineBitmap(fivePixels,combineBitmap4.offsetX 2 * width / 3 fourOffset.offsetX,combineBitmap4.offsetY fourOffset.offsetY,combineBitmap4.rightCoverWith, CoverWidth- fourOffset.offsetX);Log.d("combineBitmap", "创建完毕");int resultWidth = combineBitmap5.offsetX width;Log.d("resultWidth", Integer.toString(resultWidth));int[] resultPixels = new int[resultWidth * height];Log.d("resultPixels", "分配成功");int pixColor = 0;int layColor = 0;int pixR = 0;int pixG = 0;int pixB = 0;int pixA = 0;int layR = 0;int layG = 0;int layB = 0;int layA = 0;int newR = 0;int newG = 0;int newB = 0;int newA = 0;int checkIdx = 0;int targertIdx = 0;double ratio = 0;int Max = height * width;int resultMax = resultWidth * height;for (int h = 0; h < height; h ) {for (int w = 0; w < width - combineBitmap1.leftCoverWith; w ) {resultPixels[h * resultWidth w] = combineBitmap1.pixels[h* width w];}}for (int h = 0; h < height; h ) {for (int w = width - combineBitmap1.leftCoverWith; w < width; w ) {resultPixels[h * resultWidth w] = combineBitmap1.pixels[h* width w];}}Log.d("firstPix", "pass");combineBitmap1 = null;firstPixels = null;for (int h = 0; h < height; h ) {for (int w = 0; w < combineBitmap2.leftCoverWith; w ) {targertIdx = (h combineBitmap2.offsetY) * resultWidth w combineBitmap2.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}checkIdx = h * width w;ratio = (double) w / combineBitmap2.leftCoverWith;// 得到这个点在重叠部分的比例基数,以便实现渐变layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = combineBitmap2.pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = combineBitmap2.leftCoverWith; w < width; w ) {targertIdx = (h combineBitmap2.offsetY) * resultWidth w combineBitmap2.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}resultPixels[targertIdx] = combineBitmap2.pixels[width * h w];}}Log.d("secondPix", "pass");combineBitmap2 = null;secondPixels = null;for (int h = 0; h < height; h ) {for (int w = 0; w < combineBitmap3.leftCoverWith; w ) {targertIdx = (h combineBitmap3.offsetY) * resultWidth w combineBitmap3.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}checkIdx = h * width w;ratio = (double) w / combineBitmap3.leftCoverWith;// 得到这个点在重叠部分的比例基数,以便实现渐变layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = combineBitmap3.pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = combineBitmap3.leftCoverWith; w < width; w ) {targertIdx = (h combineBitmap3.offsetY) * resultWidth w combineBitmap3.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}resultPixels[targertIdx] = combineBitmap3.pixels[width * h w];}}Log.d("thirdPix", "pass");combineBitmap3 = null;thirdPixels = null;for (int h = 0; h < height; h ) {for (int w = 0; w < combineBitmap4.leftCoverWith; w ) {targertIdx = (h combineBitmap4.offsetY) * resultWidth w combineBitmap4.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}checkIdx = h * width w;ratio = (double) w / combineBitmap4.leftCoverWith;// 得到这个点在重叠部分的比例基数,以便实现渐变layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = combineBitmap4.pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = combineBitmap4.leftCoverWith; w < width; w ) {targertIdx = (h combineBitmap4.offsetY) * resultWidth w combineBitmap4.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}resultPixels[targertIdx] = combineBitmap4.pixels[width * h w];}}Log.d("fourpix", "pass");combineBitmap4 = null;fourPixels = null;for (int h = 0; h < height; h ) {for (int w = 0; w < combineBitmap5.leftCoverWith; w ) {targertIdx = (h combineBitmap5.offsetY) * resultWidth w combineBitmap5.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}checkIdx = h * width w;ratio = (double) w / combineBitmap5.leftCoverWith;// 得到这个点在重叠部分的比例基数,以便实现渐变layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = combineBitmap5.pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = combineBitmap5.leftCoverWith; w < width; w ) {targertIdx = (h combineBitmap5.offsetY) * resultWidth w combineBitmap5.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}resultPixels[targertIdx] = combineBitmap5.pixels[width * h w];}}Log.d("fourpix", "pass");combineBitmap5 = null;fourPixels = null;Bitmap bitmap = Bitmap.createBitmap(resultWidth, height,Bitmap.Config.RGB_565);bitmap.setPixels(resultPixels, 0, resultWidth, 0, 0, resultWidth,height);long end = System.currentTimeMillis();Log.d("Four_pic_costTime:", Long.toString(end - start));return bitmap;}private Bitmap combineForOne(Bitmap params) {int width = params.getWidth();int height = params.getHeight();int[] Pixels = CylinderFromRectangle(params);Bitmap bitmap = Bitmap.createBitmap(width, height,Bitmap.Config.RGB_565);bitmap.setPixels(Pixels, 0, width, 0, 0, width, height);return bitmap;}private Bitmap combineForThree(Bitmap[] params) {long start = System.currentTimeMillis();int width = params[0].getWidth();int height = params[0].getHeight();int[] firstPixels = CylinderFromRectangle(params[0]);int[] secondPixels = CylinderFromRectangle(params[1]);int[] thirdPixels = CylinderFromRectangle(params[2]);final Offset firstOffset = calculateOffset(firstPixels,secondPixels, width, height);final Offset secondOffset = calculateOffset(secondPixels,thirdPixels, width, height);int resultWidth = width * 3 - width * 2 / 3 - firstOffset.offsetX- secondOffset.offsetX;int[] resultPixels = new int[resultWidth * height];int pixColor = 0;int layColor = 0;int pixR = 0;int pixG = 0;int pixB = 0;int pixA = 0;int layR = 0;int layG = 0;int layB = 0;int layA = 0;int newR = 0;int newG = 0;int newB = 0;int newA = 0;int checkIdx = 0;int targertIdx = 0;int firstCoverWidth = width / 3;int secondCoverWidth = width / 3;double ratio = 0;int Max = height * width;for (int h = 0; h < height; h ) {for (int w = 0; w < width; w ) {resultPixels[h * resultWidth w] = firstPixels[h * width w];}}firstPixels = null;Log.d("firstBitmap", "the first bitmap pass!");firstCoverWidth = width / 3 firstOffset.offsetX;Log.d("firstCoverWidth", Integer.toString(firstCoverWidth));for (int h = 0; h < height; h ) {for (int w = 0; w < firstCoverWidth; w ) {checkIdx = (h firstOffset.offsetY) * width w firstOffset.offsetX;if (checkIdx < 0 || checkIdx >= Max) {continue;}ratio = (double) w / firstCoverWidth;// 得到这个点在重叠部分的比例基数,以便实现渐变targertIdx = h * resultWidth w width - firstCoverWidth;layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = secondPixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = 0; w < width - firstCoverWidth; w ) {checkIdx = (h firstOffset.offsetY) * width firstCoverWidth firstOffset.offsetX w;if (checkIdx < 0 || checkIdx >= Max) {continue;}resultPixels[h * resultWidth width w] = secondPixels[checkIdx];}}secondPixels = null;Log.d("SecondBitmap", "the Second bitmap pass!");secondCoverWidth = width / 3 secondOffset.offsetX;Log.d("secondCoverWidth", Integer.toString(secondCoverWidth));for (int h = 0; h < height; h ) {for (int w = 0; w < secondCoverWidth; w ) {checkIdx = (h firstOffset.offsetY secondOffset.offsetY)* width w firstOffset.offsetX secondOffset.offsetX;if (checkIdx < 0 || checkIdx >= Max) {continue;}ratio = (double) w / firstCoverWidth;// 得到这个点在重叠部分的比例基数,以便实现渐变targertIdx = h * resultWidth w width * 2- secondCoverWidth - firstCoverWidth;layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = thirdPixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = 0; w < width - secondCoverWidth; w ) {checkIdx = (h firstOffset.offsetY secondOffset.offsetY)* width secondCoverWidth w firstOffset.offsetX secondOffset.offsetX;if (checkIdx < 0 || checkIdx >= Max) {continue;}targertIdx = h * resultWidth 2 * width - firstCoverWidth w;try {resultPixels[targertIdx] = thirdPixels[checkIdx];} catch (Exception e) {Log.d("", Integer.toString(targertIdx));}}}thirdPixels = null;Log.d("SecondBitmap", "the Second bitmap pass!");Bitmap bitmap = Bitmap.createBitmap(resultWidth, height,Bitmap.Config.RGB_565);bitmap.setPixels(resultPixels, 0, resultWidth, 0, 0, resultWidth,height);long end = System.currentTimeMillis();Log.d("Three_pic_costTime:", Long.toString(end - start));return bitmap;}private Offset calculateOffset(int[] firstPixels, int[] secondPixels,int width, int height) {long start = System.currentTimeMillis();Offset resultOffset = new Offset(0, 0);int pixColor = 0;int layColor = 0;int pixR = 0;int pixG = 0;int pixB = 0;int pixA = 0;int layR = 0;int layG = 0;int layB = 0;int layA = 0;long sum = 0;long smallSum = Long.MAX_VALUE;int offset = width * 2 / 3;int tempWidth = width / 6;// 15用来去除掉边缘没有色彩的部分,硬编码,有待改进for (int i = -tempWidth 20; i < tempWidth - 20; i ) {// for (int j = -height / 6; j < height / 6; j ) {// 先不做Y轴的偏移。for (int j = 0; j < 1; j ) {sum = 0;for (int k = 0; k < height * 2 / 3; k ) {layColor = firstPixels[(int) (height / 6 k) * width offset tempWidth];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);pixColor = secondPixels[((int) (height / 6) j k)* width tempWidth i];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);sum = Math.pow(layR - pixR, 2);sum = Math.pow(layG - pixG, 2);sum = Math.pow(layB - pixB, 2);}if (smallSum > sum) {smallSum = sum;resultOffset.offsetX = i;resultOffset.offsetY = j;}}}Log.d("smallsum:", Long.toString(smallSum));Log.d("resultOffsetX:", Integer.toString(resultOffset.offsetX));Log.d("resultOffsetY:", Integer.toString(resultOffset.offsetY));long end = System.currentTimeMillis();Log.d("calculateOffset Cost_time:", Long.toString(end - start));return resultOffset;}private Bitmap combineForTwo(Bitmap result1, Bitmap result2) {long start = System.currentTimeMillis();int width = result1.getWidth();int height = result1.getHeight();Bitmap bitmap = Bitmap.createBitmap(width * 5 / 3, height,Bitmap.Config.RGB_565);int ResultWidth = (width * 5 / 3);int[] pixelsResult = new int[ResultWidth * height];int pixColor = 0;int layColor = 0;int pixR = 0;int pixG = 0;int pixB = 0;int pixA = 0;int layR = 0;int layG = 0;int layB = 0;int layA = 0;int newR = 0;int newG = 0;int newB = 0;int newA = 0;double RatioBase = (double) width / 3;// Log.d("aRatio", Double.toString(aRatio));double ratio = 0;int offsetX = 0;int offsetY = 0;int[] pixels = CylinderFromRectangle(result1);Log.d("get_bitmap", "获得第一张图像");for (int i = 0; i < height; i ) {for (int j = 0; j < width / 3; j ) {pixelsResult[i * ResultWidth j] = pixels[i * width j];}}Log.d("array_bound", "第一幅第一部分通过");for (int i = 0; i < height; i ) {for (int j = width / 3; j < width * 2 / 3; j ) {pixelsResult[i * ResultWidth j] = pixels[i * width j];}}Log.d("array_bound", "第一幅第二部分通过");for (int i = 0; i < height; i ) {for (int j = width * 2 / 3; j < width; j ) {pixColor = pixels[i * width j];// pixR = Color.red(pixColor);// pixG = Color.green(pixColor);// pixB = Color.blue(pixColor);// pixA = (int) (aRatio * (width - j));// pixColor = Color.argb(pixA, pixR, pixG, pixB);pixelsResult[i * ResultWidth j] = pixColor;}}Log.d("array_bound", ";第一幅第三部分通过");pixels = null;pixels = CylinderFromRectangle(result2);Log.d("get_bitmap", "获得第二张图像");int offset = width * 2 / 3;int tempWidth = width / 6;long sum = 0;long smallSum = Long.MAX_VALUE;// 15用来去除掉边缘没有色彩的部分,硬编码,有待改进for (int i = -tempWidth 15; i < tempWidth - 15; i ) {for (int j = -height / 6; j < height / 6; j ) {sum = 0;// 多条线更多匹配// for (int k = 0; k < height * 2 / 3; k ) {//// layColor = pixelsResult[(int) (height / 6 k)// * ResultWidth offset tempWidth - 5];// layR = Color.red(layColor);// layG = Color.green(layColor);// layB = Color.blue(layColor);// pixColor = pixels[((int) (height / 6) j k) * width// tempWidth i - 5];// pixR = Color.red(pixColor);// pixG = Color.green(pixColor);// pixB = Color.blue(pixColor);//// sum = Math.pow(layR - pixR, 2);// sum = Math.pow(layG - pixG, 2);// sum = Math.pow(layB - pixB, 2);//// }for (int k = 0; k < height * 2 / 3; k ) {layColor = pixelsResult[(int) (height / 6 k)* ResultWidth offset tempWidth];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);pixColor = pixels[((int) (height / 6) j k) * width tempWidth i];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);sum = Math.pow(layR - pixR, 2);sum = Math.pow(layG - pixG, 2);sum = Math.pow(layB - pixB, 2);}// for (int k = 0; k < height * 2 / 3; k ) {//// layColor = pixelsResult[(int) (height / 6 k)// * ResultWidth offset tempWidth 5];// layR = Color.red(layColor);// layG = Color.green(layColor);// layB = Color.blue(layColor);// pixColor = pixels[((int) (height / 6) j k) * width// tempWidth i 5];// pixR = Color.red(pixColor);// pixG = Color.green(pixColor);// pixB = Color.blue(pixColor);// sum = Math.pow(layR - pixR, 2);// sum = Math.pow(layG - pixG, 2);// sum = Math.pow(layB - pixB, 2);// }if (smallSum > sum) {smallSum = sum;offsetX = i;offsetY = j;// Log.d("sum:", Long.toString(smallSum));}}}Log.d("offsetX:", Integer.toString(offsetX));Log.d("offsetY:", Integer.toString(offsetY));int checkIdx = 0;int Max = width * height;// offsetY = 0;// 先屏蔽掉Y轴偏移,,不然太坑了for (int i = 0; i < height; i ) {for (int j = 0; j < width / 3; j ) {ratio = (double) j / RatioBase;layColor = pixelsResult[i * ResultWidth j offset];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);checkIdx = (i offsetY) * width j offsetX;if (checkIdx < 0 || checkIdx >= Max) {continue;}pixColor = pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));pixelsResult[i * ResultWidth j offset] = Color.rgb(newR, newG, newB);}}Log.d("array_bound", "第二幅第一部分通过");for (int i = 0; i < height; i ) {for (int j = width / 3; j < width * 2 / 3; j ) {checkIdx = (i offsetY) * width j offsetX;if (checkIdx < 0 || checkIdx >= Max) {continue;}pixColor = pixels[checkIdx];pixelsResult[i * ResultWidth j offset] = pixColor;}}Log.d("array_bound", "第二幅第二部分通过");for (int i = 0; i < height; i ) {for (int j = width * 2 / 3; j < width; j ) {checkIdx = (i offsetY) * width j offsetX;if (checkIdx < 0 || checkIdx >= Max) {continue;}pixColor = pixels[checkIdx];pixelsResult[i * ResultWidth j offset] = pixColor;}}Log.d("array_bound", "第二幅第三部分通过");pixels = null;bitmap.setPixels(pixelsResult, 0, ResultWidth, 0, 0, ResultWidth,height);long end = System.currentTimeMillis();Log.d("Three_pic_costTime:", Long.toString(end - start));return bitmap;}private Bitmap combineForFour(Bitmap[] params) {long start = System.currentTimeMillis();int width = params[0].getWidth();int height = params[0].getHeight();int[] firstPixels = CylinderFromRectangle(params[0]);int[] secondPixels = CylinderFromRectangle(params[1]);int[] thirdPixels = CylinderFromRectangle(params[2]);int[] fourPixels = CylinderFromRectangle(params[3]);final Offset firstOffset = calculateOffset(firstPixels,secondPixels, width, height);final Offset secondOffset = calculateOffset(secondPixels,thirdPixels, width, height);final Offset thirdOffset = calculateOffset(thirdPixels, fourPixels,width, height);int CoverWidth = width / 3;// int secondCoverWidth = width / 3;Log.d("offset", "计算完毕");CombineBitmap combineBitmap1 = new CombineBitmap(firstPixels, 0, 0,0, CoverWidth - firstOffset.offsetX);CombineBitmap combineBitmap2 = new CombineBitmap(secondPixels, 2* width / 3 firstOffset.offsetX, firstOffset.offsetY,CoverWidth - firstOffset.offsetX, CoverWidth- secondOffset.offsetX);CombineBitmap combineBitmap3 = new CombineBitmap(thirdPixels,combineBitmap2.offsetX 2 * width / 3 secondOffset.offsetX, combineBitmap2.offsetY secondOffset.offsetY,combineBitmap2.rightCoverWith, CoverWidth- thirdOffset.offsetX);CombineBitmap combineBitmap4 = new CombineBitmap(fourPixels,combineBitmap3.offsetX 2 * width / 3 thirdOffset.offsetX, combineBitmap3.offsetY thirdOffset.offsetY,combineBitmap3.rightCoverWith, CoverWidth- thirdOffset.offsetX);Log.d("combineBitmap", "创建完毕");int resultWidth = combineBitmap4.offsetX width;Log.d("resultWidth", Integer.toString(resultWidth));int[] resultPixels = new int[resultWidth * height];Log.d("resultPixels", "分配成功");int pixColor = 0;int layColor = 0;int pixR = 0;int pixG = 0;int pixB = 0;int pixA = 0;int layR = 0;int layG = 0;int layB = 0;int layA = 0;int newR = 0;int newG = 0;int newB = 0;int newA = 0;int checkIdx = 0;int targertIdx = 0;double ratio = 0;int Max = height * width;int resultMax = resultWidth * height;for (int h = 0; h < height; h ) {for (int w = 0; w < width - combineBitmap1.leftCoverWith; w ) {resultPixels[h * resultWidth w] = combineBitmap1.pixels[h* width w];}}for (int h = 0; h < height; h ) {for (int w = width - combineBitmap1.leftCoverWith; w < width; w ) {resultPixels[h * resultWidth w] = combineBitmap1.pixels[h* width w];}}Log.d("firstPix", "pass");combineBitmap1 = null;firstPixels = null;for (int h = 0; h < height; h ) {for (int w = 0; w < combineBitmap2.leftCoverWith; w ) {targertIdx = (h combineBitmap2.offsetY) * resultWidth w combineBitmap2.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}checkIdx = h * width w;ratio = (double) w / combineBitmap2.leftCoverWith;// 得到这个点在重叠部分的比例基数,以便实现渐变layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = combineBitmap2.pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = combineBitmap2.leftCoverWith; w < width; w ) {targertIdx = (h combineBitmap2.offsetY) * resultWidth w combineBitmap2.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}resultPixels[targertIdx] = combineBitmap2.pixels[width * h w];}}Log.d("secondPix", "pass");combineBitmap2 = null;secondPixels = null;for (int h = 0; h < height; h ) {for (int w = 0; w < combineBitmap3.leftCoverWith; w ) {targertIdx = (h combineBitmap3.offsetY) * resultWidth w combineBitmap3.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}checkIdx = h * width w;ratio = (double) w / combineBitmap3.leftCoverWith;// 得到这个点在重叠部分的比例基数,以便实现渐变layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = combineBitmap3.pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = combineBitmap3.leftCoverWith; w < width; w ) {targertIdx = (h combineBitmap3.offsetY) * resultWidth w combineBitmap3.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}resultPixels[targertIdx] = combineBitmap3.pixels[width * h w];}}Log.d("thirdPix", "pass");combineBitmap3 = null;thirdPixels = null;for (int h = 0; h < height; h ) {for (int w = 0; w < combineBitmap4.leftCoverWith; w ) {targertIdx = (h combineBitmap4.offsetY) * resultWidth w combineBitmap4.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}checkIdx = h * width w;ratio = (double) w / combineBitmap4.leftCoverWith;// 得到这个点在重叠部分的比例基数,以便实现渐变layColor = resultPixels[targertIdx];layR = Color.red(layColor);layG = Color.green(layColor);layB = Color.blue(layColor);layA = Color.alpha(layColor);pixColor = combineBitmap4.pixels[checkIdx];pixR = Color.red(pixColor);pixG = Color.green(pixColor);pixB = Color.blue(pixColor);pixA = Color.alpha(pixColor);// layA = Color.alpha(pixColor);if (pixA == 0) {newR = layR;newG = layG;newB = layB;} else if (layA == 0) {newR = pixR;newG = pixG;newB = pixB;} else {newR = (int) (ratio * pixR * (pixA / 255) (1 - ratio)* layR * (layA / 255));newG = (int) (ratio * pixG * (pixA / 255) (1 - ratio)* layG * (layA / 255));newB = (int) (ratio * pixB * (pixA / 255) (1 - ratio)* layB * (layA / 255));}// newA = pixA;newR = Math.min(255, Math.max(newR, 0));newG = Math.min(255, Math.max(newG, 0));newB = Math.min(255, Math.max(newB, 0));resultPixels[targertIdx] = Color.rgb(newR, newG, newB);}}for (int h = 0; h < height; h ) {for (int w = combineBitmap4.leftCoverWith; w < width; w ) {targertIdx = (h combineBitmap4.offsetY) * resultWidth w combineBitmap4.offsetX;if (targertIdx < 0 || targertIdx > resultMax) {continue;}resultPixels[targertIdx] = combineBitmap4.pixels[width * h w];}}Log.d("fourpix", "pass");combineBitmap4 = null;fourPixels = null;Bitmap bitmap = Bitmap.createBitmap(resultWidth, height,Bitmap.Config.RGB_565);bitmap.setPixels(resultPixels, 0, resultWidth, 0, 0, resultWidth,height);long end = System.currentTimeMillis();Log.d("Four_pic_costTime:", Long.toString(end - start));return bitmap;}private class Offset {int offsetX;int offsetY;public Offset(int x, int y) {offsetX = x;offsetY = y;}};@Overrideprotected void onPreExecute() {mProgressDialog = ProgressDialog.show(MypanoramaActivity.this,"正在处理图像", "请耐心等待", true, false);}@Overrideprotected void onPostExecute(Bitmap result) {mProgressDialog.dismiss();for (Bitmap bitmap : bitmaps) {bitmap.recycle();}bitmaps.clear();resultBitmap = result;createDialog();}private void createDialog() {// TODO Auto-generated method stub\View saveDialog = getLayoutInflater().inflate(R.layout.save, null);photonameEditText = (EditText) saveDialog.findViewById(R.id.phone_name);ImageView imageView = (ImageView) saveDialog.findViewById(R.id.show);imageView.setImageBitmap(resultBitmap);new AlertDialog.Builder(MypanoramaActivity.this).setView(saveDialog).setPositiveButton(getString(R.string.text_save),saveClickListener).setNegativeButton(getString(R.string.text_cancel),cancelClickListener).show();}private OnClickListener cancelClickListener = new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {long rowId = savePicture("", resultBitmap);// Intent intent = new Intent(MypanoramaActivity.this,// EffectPhotoActivity.class);// intent.putExtra(PhotoDbAdapter.KEY_ROWID, rowId);// startActivity(intent);MypanoramaActivity.this.finish();}};private OnClickListener saveClickListener = new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {String string = photonameEditText.getText().toString();long rowId = savePicture(string, resultBitmap);Intent intent = new Intent(MypanoramaActivity.this,EffectPhotoActivity.class);intent.putExtra(PhotoDbAdapter.KEY_ROWID, rowId);Log.d("rowId", Long.toString(rowId));startActivity(intent);MypanoramaActivity.this.finish();}};}private long savePicture(String name, Bitmap bm) {String pathString = (name == "" ? Const.PHOTO_NAME_STRING (int) z: name) ".jpg";File dirFile = new File(Const.PIC_PATH);long RowId = 0;if (!dirFile.exists()) {dirFile.mkdirs();}File file = new File(Const.PIC_PATH, pathString);BufferedOutputStream bos = null;try {bos = new BufferedOutputStream(new FileOutputStream(file));bm.compress(CompressFormat.JPEG, 100, bos);bos.flush();bos.close();PhotoDbAdapter photoDbAdapter = new PhotoDbAdapter(MypanoramaActivity.this);photoDbAdapter.open();RowId = photoDbAdapter.createPhoto(file.getName(), file.getPath());photoDbAdapter.close();} catch (Exception e) {} finally {bos = null;}return RowId;}private int[] CylinderFromRectangle(Bitmap taskBitmap) {long start = System.currentTimeMillis();int width = taskBitmap.getWidth();int height = taskBitmap.getHeight();Bitmap bitmap = Bitmap.createBitmap(width, height,Bitmap.Config.RGB_565);double r = (double) width / Math.tan(Math.toRadians(30));Log.d("半径:", "半径:" r);double a;int x;int y;int pixcolor = 0;int idx;int idx2;int[] pixels = new int[width * height];// int lucency = Color.argb(0, 0, 0, 0);// Log.d("lucency:", Integer.toString(lucency));int[] pixelsResult = new int[width * height];// for (int i = 0; i < pixelsResult.length; i ) {// pixelsResult[i] = lucency;// }taskBitmap.getPixels(pixels, 0, width, 0, 0, width, height);for (int i = -width / 2; i < width / 2; i ) {a = Math.atan(i / r);x = (int) (a * r);for (int j = height / 2; j > -height / 2; j--) {y = (int) (j * Math.cos(a));idx = (i width / 2) (height / 2 - j) * width;idx = Math.min(width * height - 1, Math.max(0, idx));pixcolor = pixels[idx];idx2 = x width / 2 (height / 2 - y) * width;idx2 = Math.min(width * height - 1, Math.max(0, idx2));pixelsResult[idx2] = pixcolor;}}pixels = null;// bitmap.setPixels(pixelsResult, 0, width, 0, 0, width, height);long end = System.currentTimeMillis();Log.d("effect_cost_time", "costTime:" (end - start));return pixelsResult;}}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复